package com.zf.museum.controller;

import com.zf.museum.bean.Result;
import com.zf.museum.model.Message;
import com.zf.museum.service.MessageService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 添加闯关提示语
     * @param message
     * @return
     */
    @PostMapping("/addMessage")
    @RequiresRoles("admin")
    public Result addMessage(@RequestBody Message message) {

        return messageService.addMessage(message);
    }

    /**
     * 批量更新闯关提示语
     * @param messages
     * @return
     */
    @PostMapping("/updateMessages")
    @RequiresRoles("admin")
    public Result updateMessages(@RequestBody ArrayList<Message> messages) {

        return messageService.updateMessages(messages);
    }

    /**
     * 根据id删除message
     * @return
     */
    @DeleteMapping("/deleteById")
    @RequiresRoles("admin")
    public Result deleteById(@RequestParam("id") Long id) {

        return messageService.deleteById(id);
    }

    /**
     * 获取所有的提示语
     * @return
     */
    @GetMapping("/findAll")
    @RequiresRoles("admin")
    public List<Message> findAll() {

        return messageService.findAll();
    }
}
